package com.yunhe.option.repository.base;

import com.yunhe.option.domain.base.Enum;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @ClassName EnumRepository
 * @Description TODO
 * @Author HeTao
 * @Date 2021/2/26 14:30
 * @Version 1.0
 **/
@Repository
public interface EnumRepository extends Neo4jRepository<Enum, Long> {
    Enum findByName(String name);

    @Query(value="match(e:Enum) return e order by e.sn desc",
            countQuery="match(e:Enum) return count(e) order by e.sn desc" )
    Page<Enum> findAllEnums(Pageable pageable);

    @Query("match(e:Enum) return e order by e.sn desc")
    Iterable<Enum> findAllEnums();

    @Query("MATCH (children:Item)<-[:HAS_CHILD*0..9]-(parent:Item)<-[:HAS_ITEM]-(e:Enum)  where ID(children)={itemId}" +
            "RETURN e")
    Enum findEnumByItemId(@Param("itemId") Long itemId);
}
